Compromising SSH keys using telnet

We will compromise a client’s private key (like msfadmin) present on Metasploitable2.

  1. Connect to Metasploitable2 using

telnet [IP]

  1. Login using msfadmin

  2. Go to the directory (.ssh) where ssh keys are stored

cd /home/msfadmin/.ssh

a675a6fea2612d8898821b262fda4f40.png

  1. List all files in the directory with details

ls -l

There will be three files in it:

eb5ca30d238b641dd28c013643b6f0f2.png

410e0e2b1b4a43af9ab9326601005c7b.png

  1. Print the private key

cat id_rsa

4e496f47a80e887db20f4e3bc50d1a7a.png

Copy the output on the screen to a file on your desktop, save with the name it id_rsa (or anything else)

994ad22f74ea228c6f9bb3b6d0d727c3.png

  1. Close connection

exit


Note: They key should have 600 permission only and by default ssh uses id_rsa named key file only for login, to use a key file with different name use -i option in ssh.

Change key's permission to 600

chmod 600 [key file name]

600 - Read + Write for user and no persmissions for group and others.

Use key with different name

ssh -i [key file name] [user@IP]

-i identity_file
Selects a file from which the identity (private key) for public key authentication is read. The default is ~/.ssh/id_dsa,id_ecdsa, id_ecdsa_sk,id_ed25519,id_ed25519_sk and id_rsa.


Login using the key

I've renamed the key to ms_key and changed it's permissions.
We will login as root since it is not possible to login as user or msfadmin.

10a3f42bcead1576ba63e6750f8184f6.png

/etc/ssh holds the private and public key pairs for the host (the computer/operating system) like server.

1c8a03e78bc3ae3f67fe8af24b4d98c4.png

~/.ssh holds the key pairs for the users like clients.